#include "TCPServer.hpp"
#include "Command.hpp"

/*
    Server端
    1. version1：Echo
    2. version2：在线翻译
    3. version3：在线命令行执行
*/

// 1. version1：Echo 
std::string defaulthandler(const std::string &message, InterAddr &addr)
{
    LOG(LogLevel::DEBUG) << addr.AddrName() << "回调到了defaulthandler";
    std::string s = "haha, ";
    s += message;
    return s;
}

// 调用方式 ./TCPServer port
int main(int argc, char *argv[])
{
    if(argc != 2)
    {
        std::cerr << "User: " << argv[0] << " port";
        exit(CALL_ERR);
    }

    uint16_t port = std::stoi(argv[1]);

    // 1. version1：Echo 
    // std::unique_ptr<TCPServer> tsver = std::make_unique<TCPServer>(port, defaulthandler);

    // 2. version2：在线翻译
    // Dict d;
    // d.LoadDict();
    // std::unique_ptr<TCPServer> tsver = std::make_unique<TCPServer>(port, [&d](const std::string &word, InterAddr &addr)->std::string{
    //     return d.Translate(word, addr);
    // });

    //  3. version3：在线命令行执行
    Command c;
    std::unique_ptr<TCPServer> tsver = std::make_unique<TCPServer>(port, [&c](const std::string &cmd, InterAddr &addr)->std::string{
        return c.Execute(cmd, addr);
    });

    
    tsver->Init();
    tsver->Run();

    return 0;
}